// 获取页面数据
var resData = '';
var param   = {'operation':'userBindBankCard', 'data':''};
function do_post(param){
	$.ajax({
		type:'post',
		url: getDataUrl,
		data:'data=' + JSON.stringify(param),
		cache:false,
		dataType:'json',
		async:false,
		success:function(res){
			if(res.msg){
				showMsg('温馨提示', res.msg, 'index.php?m=member&c=manageBankcard');
			}else{
				resData = res;
			}
		}
	})
}
function showMsg(title, content, href){
	layer.open({
		title: title,
		content: content,
		className: 'layui-m-tag-msg',
		btn: ['确定'],
		yes: function (index){
			// 继续投注
			layer.close(index);
			if(href){
				window.location.href= href;
			}
		},
	});
}
console.log(resData);

//用户输入的银行卡信息验证

//用户银行信息保存
var dataJson = {}

//开户银行验证
$('#id_account_city').on('click', function (){
	var bankid = $("#id_account_bankid").val();
	if(bankid=="0"){
		showMsg('温馨提示', "请选择开户银行");
	}else{
		dataJson.bank = bankid;
	}
})

//开户城市验证
$("#id_account_name").on("focus",function(){
	$(this).val("");
	var province = $('#id_account_city').val().split('-')[0];
	var city = $('#id_account_city').val().split('-')[1];
	if(!province){
		showMsg('温馨提示', "请选择开户省");
	}else{
		dataJson.province  = province;
	}
	if(!city){
		showMsg('温馨提示', "请选择开户市");
	}else{
		dataJson.city  = city;
	}
})


//开户人姓名验证
$("#id_account_num").on("focus",function(){
	var truename = $('#id_account_name').val();
	var pattern = /^[\u4e00-\u9fa5]+$/g;
	var flag = pattern.test(truename);
	if(!truename){
		showMsg('温馨提示', "请输入开户人姓名");
	}else if(!flag){
		showMsg('温馨提示', "开户人姓名必须是汉字");
	}else{
		dataJson.truename  = truename;
	}
})

//银行卡号验证
$("#id_account_num_ry").on("focus",function(){
	
	var bankcard = $('#id_account_num').val();
	var pattern =  /^\d{19}$/g;
	if(!bankcard){
		showMsg('温馨提示', "银行卡卡号不能为空");
	}else if(!pattern.test(bankcard)){
		showMsg('温馨提示', "银行卡卡号必须是19位数字");
	}else{
		dataJson.bankcard  = bankcard;
	}
})

//重复银行卡号验证
$("#id_account_password").on("focus",function(){
	$(this).attr("type","password");
	var bankcardAgian = $('#id_account_num_ry').val();
	var bankcard = $('#id_account_num').val();
	var pattern =  /^\d{19}$/g;
	var flag = pattern.test(bankcardAgian);
	if(!bankcardAgian){
		showMsg('温馨提示', "重复银行卡卡号不能为空");
	}else if(!flag){
		showMsg('温馨提示', "重复银行卡卡号必须是19位数字");
	}else if(bankcardAgian !=bankcard){
		showMsg('温馨提示', "重复银行卡卡号不相同");
	}
})

$('#id_sub_bind').on('click', '', function (){
	//安全密码验证
	var security = $('#id_account_password').val();
	if(!security){
		showMsg('温馨提示', "请设置安全密码");
		return false;
	}else{
		dataJson.security = security;
	}
	param.data = dataJson;
	do_post(param);
});

//开户城市
var cityData = '';
var sheng    = '';
var shi      = '';
$.ajax({
	type:'get',
	url: "/static/js/member/city.json",
	cache:false,
	dataType:'json',
	async:false,
	success:function(res){
		cityData = res;
	}
})
var str = '';
$('#id_city_item').html('');
$('#id_city_item_2').html('');
$.each(cityData, function (i, v){
	str = '<a class="tag_choice_city_item">' + i + '</a>';
	$('#id_city_item').append(str);
});
$('#id_city_item').on('click', '.tag_choice_city_item', function (){
	$('.tag_choice_city_item').removeClass('Areas');
	$(this).addClass('Areas');
	$('#id_account_city').val( $(this).html() );
	sheng = cityData[$(this).html()];
	// 隐藏省，显示市
	$('.tag_city_box:eq(0)').hide();
	$('#id_shengshi_item li').eq(1).addClass("citySel").siblings().removeClass("citySel")
	$('.tag_city_box').eq(1).html("");
	$.each(sheng, function (i, v){
		str = '<a class="tag_choice_city_item">' + i + '</a>';
		$('#id_city_item_2').append(str);
	})
	$('.tag_city_box:eq(1)').show();
})

$('#id_city_item_2').on('click', '.tag_choice_city_item', function (){
	$('#id_account_city').val( $('#id_account_city').val() + '-' + $(this).html() );
	$('#id_city_choice').hide();
})
$('#id_account_city').on('click', function (){
	$('.tag_city_box').hide();
	$('.tag_city_box:eq(0)').show();
	$('#id_shengshi_item li').eq(0).addClass("citySel").siblings().removeClass("citySel")
	$('.tag_choice_city_item').removeClass('Areas');
	$('#id_city_item_2').html('');
	$('#id_account_city').val('');
	$('#id_city_choice').show();
})
$('#id_shengshi_item li').on('click', function (){
	$('.tag_city_box').hide();
	$(this).addClass("citySel").siblings().removeClass("citySel")
	var index = $(this).index();
	if(!index){
		$('.tag_city_box').eq(index).show();
	}else{
		//判断是否已经选择了省
		var province = $('#id_account_city').val().split('-')[0];
		if(!province){
			showMsg('温馨提示', "请先选择省份");
			return false;
		}
		$('#id_shengshi_item li').eq(index).addClass("citySel").siblings().removeClass("citySel")
		sheng = cityData[province];
		// 隐藏省，显示市
		$('.tag_city_box').eq(1).html("");
		$.each(sheng, function (i, v){
			str = '<a class="tag_choice_city_item">' + i + '</a>';
			$('#id_city_item_2').append(str);
		})
		$('.tag_city_box').eq(1).show();
	}
	
	
	
	
	
	
	
})
$('#id_close').on('click', '', function (){
	$('#id_city_choice').hide();
})